package dao.impl;

import dao.BaseDao;
import dao.orderDao;
import prjo.dishMeg;
import prjo.order;

import java.sql.Connection;
import java.util.List;

/**
 * @author shkstart
 * @creat 16:35 2022/6/3
 */

public class orderImpl extends BaseDao implements orderDao {


    dishImpl dish = new dishImpl();

    /**
     * String name,String dishMeg,int time,String address,int status,int sumPrice
     *
     * @param args
     * @return
     */
    @Override
    public int addOrder(Connection conn, String name, dishMeg dishMeg, int time, String address, int status) {
        int Price = dishMeg.getDish().getPrice();
        int num = dishMeg.getNum();
        int sumPrice = Price * num;
        if (sumPrice <= 50) {
            sumPrice += 5;
        }
        String sql = "insert into `order` (name,dishMeg,time,address,status,sumPrice) values(?,?,?,?,?,?)";
        Object[] args = {name, dishMeg.toString(), time, address, 0, sumPrice};
        return update(conn, sql, args);
    }

    @Override
    public List<order> showOrder(Connection conn) {
        String sql = "select * from `order`";
        return getForList(conn, prjo.order.class, sql);
    }

    @Override
    public int getOrder(Connection conn, int id) {
        String sql = "update `order` set status = 1 where id = ?";
        return update(conn, sql, id);
    }

    @Override
    public int deleterOrder(Connection conn, int id) {
        String sql = "delete from `order` where id = ?";
        return update(conn, sql, id);
    }

    @Override
    public order OneOrder(Connection conn, int id) {
        String sql = "select * from `order` where id = ?";
        return getInstance(conn, order.class, sql, id);
    }
}
